package team.knowers.qzh.qzhadmin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;
import team.knowers.qzh.qzhadmin.dao.entity.SectionDO;
import team.knowers.qzh.qzhadmin.dao.mapper.SectionMapper;
import team.knowers.qzh.qzhadmin.dto.resp.AllSectionRespDTO;
import team.knowers.qzh.qzhadmin.service.SectionAdminService;

import java.util.ArrayList;
import java.util.List;

@Service
@AllArgsConstructor
public class SectionAdminServiceImpl extends ServiceImpl<SectionMapper, SectionDO> implements SectionAdminService {
    @Override
    public List<AllSectionRespDTO> showSection(Long id) {
        LambdaQueryWrapper<SectionDO> queryWrapper = Wrappers.lambdaQuery(SectionDO.class)
                .eq(SectionDO::getChapterId, id)
                .eq(SectionDO::getDelFlag, 0)
                .eq(SectionDO::getVersion,0)
                .orderByAsc(SectionDO::getOrder);

        List<SectionDO> sectionDOS = baseMapper.selectList(queryWrapper);
        List<AllSectionRespDTO> sectionDTOs = new ArrayList<>();

        for (SectionDO sectionDO : sectionDOS) {
            AllSectionRespDTO sectionDTO = new AllSectionRespDTO();
            sectionDTO.setOrder(sectionDO.getOrder());
            sectionDTO.setId(sectionDO.getId());
            sectionDTO.setSectionNumber(sectionDO.getSectionNumber());
            sectionDTO.setName(sectionDO.getName());
            sectionDTOs.add(sectionDTO);
        }

        return sectionDTOs;
    }
}
